import View from "./view";
import AssetsLoader from "./assets_loader";

export default class Bitmap extends View {
  className = "AXEBitmap";
  clone() {
    let e = this,
      t = new Bitmap();
    return e.copyProperties(t), t;
  }
  copyProperties(t) {
    let n = this;
    View.prototype.copyProperties.call(n, t),
      t.fixSize(n.fixSize()),
      t.bitmap(n.bitmap());
  }
  dealloc() {
    let t = this;
    (t._bitmap = null), View.prototype.dealloc.call(t);
  }
  updatePropsFromXML(n) {
    let r = this;
    View.prototype.updatePropsFromXML.call(r, n),
      r.fixSize(n.is("[width]") && n.is("[height]")),
      n.is("[src]") && r.bitmap(AssetsLoader.asset(n.attr("src")));
  }
  updateSize() {
    let e = this;
    e.bitmap() != null &&
      (e.fixSize() == 0
        ? (e.width(e.bitmap().naturalWidth), e.height(e.bitmap().naturalHeight))
        : ((e.bitmap().width = e.width()), (e.bitmap().height = e.height())));
  }
  _fixSize = !1;
  fixSize(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        e != t._fixSize &&
        ((t._fixSize = e), t.updateSize(), t.needToRender(!0)),
      t._fixSize
    );
  }
  _bitmap = null;
  bitmap(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        e != t._bitmap &&
        ((t._bitmap = e), t.updateSize(), t.needToRender(!0)),
      t._bitmap
    );
  }
}
